extends Control

@onready var exit_btn : Button = $ColorRect/MarginContainer/VBoxContainer/CenterContainer/VBoxContainer/ExitBtn
@onready var view_catalog_btn : Button = $ColorRect/MarginContainer/VBoxContainer/CenterContainer/VBoxContainer/ViewCatalogBtn
@onready var preferences_btn : Button = $ColorRect/MarginContainer/VBoxContainer/CenterContainer/VBoxContainer/PreferencesBtn
@onready var cellect_catalog_lbl : Label = $ColorRect/MarginContainer/VBoxContainer/CenterContainer/VBoxContainer/SellectCatalogLabel

# Called when the node enters the scene tree for the first time.
func _ready():
	
	view_catalog_btn.pressed.connect(_view_catalog)
	preferences_btn.pressed.connect(func():get_tree().change_scene_to_file("res://preferences_page/preferences_page.tscn"))
	exit_btn.pressed.connect(_exit)

func _input(event):
	if event.is_action_pressed("ui_cancel"):
		_exit()


func _exit():get_tree().quit()
func _view_catalog():
	if not ENV.current_catalog_path.is_empty():
		get_tree().change_scene_to_file("res://view_catalog/view_catalog.tscn")
	else:
		cellect_catalog_lbl.visible = true
		var timer := Timer.new()
		timer.one_shot = true
		timer.wait_time = 2
		timer.timeout.connect(func(): cellect_catalog_lbl.visible = false; remove_child(timer))
		add_child(timer)
		timer.start()
